<template>
  <view class="main u-flex">
    <u-navbar
      :title="params.customerName"
      back-icon-color="#fff"
      title-color="#fff"
      :background="{ backgroundColor: 'rgb(61, 95, 255)' }"
    >
    </u-navbar>
    <iframe ref="guardIframe" :src="url" id="guardIframe" frameborder="0" class="body" @load="loadClose"></iframe>
  </view>
</template>

<script>
import { BASE_URL } from "@/utils/ip.js";

export default {
  data() {
    return {
      url: "",
      params: {},
      disposal_code_arr: ["12", "08", "07", "06", "19", "33"],
      guardConfig: {},
    };
  },
  async onLoad(obj) {
    await this.getGuardConfig();
    this.params = JSON.parse(obj.item);
    //
    let url = "";
    switch (this.params.functionCode) {
      case "01":
        url = "monitoringData";
        break;
      case "02":
        url = "phone_charts";
        break;
      case "03":
        url = "abnormalCalibration";
        break;
      case "20":
        url = "ventilationUnit";
        break;
      case "19":
        url = "gasRealTime";
        break;
      case "18":
        url = "abnormalFeed";
        break;
      case "04":
        url = "abnormalDischarge";
        break;
      case "05":
        url = "abnormalDecline";
        break;
      case "09":
        url = "calibrationCycle";
        break;
      case "11":
        url = "coEmission";
        break;
      case "17":
        url = "gasWave";
        break;
      case "10":
        url = "batchOffline";
        break;
      case "21":
        url = "gasChangeAbnormal";
        break;
      case "22":
        url = "gasConstantVal";
        break;
      case "23":
        if (this.params?.detailType === "lj") {
          url = "avgGasChart";
        } else {
          url = "dayGasChart";
        }
        break;
      case "24":
        url = "coAndPiping";
        break;
      case "25":
        url = "coAndPiping";
        break;
      case "26":
        url = "coAndPiping";
        break;
      case "27":
        url = "personnelEnteringWell";
        break;
      case "28":
        url = "shiftLeaderHandover";
        break;
      case "29":
        url = "personnelWellInspection";
        break;
      case "30":
        url = "lockoutCycle";
        break;
      case "31":
        url = "coCalibrationCycle";
        break;
      case "34":
        url = "windSpeed";
        break;
      case "35":
        url = "airVolume";
        break;
    }
    if (this.disposal_code_arr.includes(this.params.functionCode)) {
      url = "commonDispose";
    }
    let href = "http://localhost:7078";
    // let href = "http://192.168.50.53:7076";
    const parent = {
      superviseLevel: getApp().globalData.userInfoData.superviseLevel,
      userId: getApp().globalData.userInfoData.id,
      userDataType: getApp().globalData.userInfoData.dataType,
      userCountyNo: getApp().globalData.userInfoData.countyNo,
      personnelId: getApp().globalData.userInfoData.personnelId,
      personnelName: getApp().globalData.userInfoData.personnelName,
      isApp: true,
      isJt: !this.params.isJtMine,
      isJtMine: this.params.isJtMine,
    };
    // let base_url = href; // 本地测试用
    let base_url = this.guardConfig.guard_url;
    if (this.disposal_code_arr.includes(this.params.functionCode)) {
      this.url = `${base_url}/#/${url}?id=${this.params.id}&isDisposal=true&params=${JSON.stringify(
        this.params
      )}&parent=${JSON.stringify(parent)}`;
    } else {
      this.url = `${base_url}/#/${url}?id=${this.params.id}&parent=${JSON.stringify(parent)}`;
    }
    this.iframeLoad();
  },
  methods: {
    async getGuardConfig() {
      const { body } = await this.$get("/monitor/getVueConfig");
      this.guardConfig = body;
    },
    iframeLoad() {
      uni.showLoading({ title: "加载中...", mask: true });
      this.$nextTick(() => {
        const iframe = this.$refs.guardIframe;
        if (iframe.attachEvent) {
          // IE
          iframe.attachEvent("onload", () => {
            uni.hideLoading();
          });
        } else {
          // 非IE
          iframe.onload = () => {
            uni.hideLoading();
          };
        }
      });
    },
    loadClose() {
      uni.hideLoading();
    },
  },
};
</script>
<style lang="scss" scoped>
.body {
  width: 100%;
  height: 100%;
}
.iframe-box {
  background: #eee;
  display: flex;
  flex-direction: column;
}
</style>
